package cn.java71.entity;

import java.io.Serializable;
import java.util.*;
/**
 * 代表一页数据
 * @author oldliu
 * @since 1.0
 */
public class Page<T> implements Serializable {
    public static final int PAGE_SIZE=20;//默认页大小
    //本页数据
    private List<T> datas=new ArrayList<>(0);
    private int pageNo;//当前页
    private int totalLines;//总条数
    private int totalPages;//总页数
    private int pageSize=PAGE_SIZE;
    public Page(){

    }

    public Page(List<T> datas, int pageNo, int totalLines) {
        this.datas = datas;
        this.pageNo = pageNo;
        this.totalLines = totalLines;
        //计算pages
        this.totalPages=totalLines/pageSize+(totalLines%pageSize==0?0:1);
    }
    public Page(List<T> datas, int pageNo, int totalLines,int pageSize) {
        this.datas = datas;
        this.pageNo = pageNo;
        this.totalLines = totalLines;
        this.pageSize=pageSize;
        //计算pages
        this.totalPages=totalLines/pageSize+(totalLines%pageSize==0?0:1);
    }
    public Page(List<T> datas, int pageNo, int totalLines, int totalPages, int pageSize) {
        this.datas = datas;
        this.pageNo = pageNo;
        this.totalLines = totalLines;
        this.totalPages = totalPages;
        this.pageSize = pageSize;

        //计算pages
        this.totalPages=totalLines/pageSize+(totalLines%pageSize==0?0:1);
    }

    public List<T> getDatas() {
        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getTotalLines() {
        return totalLines;
    }

    public void setTotalLines(int totalLines) {
        this.totalLines = totalLines;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
}
